package cn.iocoder.yudao.module.shop.info.vo;

import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.module.api.promotion.coupon.dto.CouponTemplateRespDTO;
import cn.iocoder.yudao.module.api.promotion.groupon.dto.GrouponPackageRespDTO;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.constant.DictTypeConstants.SCORE_LEVEL;

@Schema(description = "店铺信息 Response VO")
@Data
public class AppShopInfoVO extends ShopInfoVO {

    @Schema(description = "累计销量", example = "1024")
    private Integer salesCount;

    @Schema(description = "月度销量", example = "1024")
    private int salesCountPerMonth;

    @Schema(description = "累计浏览量", example = "1024")
    private Integer browseCount;

    @Schema(description = "配送时长，单位：分钟。小于等于0表示不支持配送。", example = "30")
    private int deliveryMinute;

    @Schema(description = "起送金额，单位：分。小于等于0表示不支持配送。", example = "1000")
    private int deliveryMinPrice;
    @Schema(description = "起送金额，单位：元。小于等于0表示不支持配送。", example = "10.00")
    private String deliveryMinPriceFormat;

    @SuppressWarnings("unused")
    public String getDeliveryMinPriceFormat() {
        return MoneyUtils.fenToYuanStr(deliveryMinPrice);
    }

    @Schema(description = "人均消费金额，单位：分", example = "1")
    private int avgConsumePrice;
    @Schema(description = "人均消费金额，单位：元", example = "0.01")
    private String avgConsumePriceFormat;

    @SuppressWarnings("unused")
    public String getAvgConsumePriceFormat() {
        return MoneyUtils.fenToYuanStr(avgConsumePrice);
    }

    @Schema(description = "下单范围半径，单位：米。小于等于0表示不限制。", example = "5000")
    private Integer o2oRadius;

    @Schema(description = "优惠卷模板列表")
    private List<CouponTemplateRespDTO> coupons;

    @Schema(description = "团购套餐列表")
    private List<GrouponPackageRespDTO> grouponPackages;

    @Schema(description = "评分", example = "5.0")
    private float score;
    @Schema(description = "评分星级：0-5", example = "0")
    @DictFormat(SCORE_LEVEL)
    private Integer scoreLevel;

    @Schema(description = "评价数，详情页才会返回", example = """
            { "allCount" : 0, "positiveCount" : 0, "negativeCount" : 0, "hasPictureCount" : 0}
            """)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Map<String, Integer> commentCount;

    @Schema(description = "是否关注", example = "false")
    @JsonProperty("follow")
    private boolean isFollow;

    @Schema(description = "是否新店", example = "false")
    @JsonProperty("new")
    private boolean isNew;

    @SuppressWarnings("unused")
    @JsonProperty("new")
    public boolean isNew() {
        return getEnterTime() != null && DateUtils.differentDays(getEnterTime(), LocalDateTime.now()) <= 30;
    }

    @Schema(description = "距离，单位：米。只有列表才会计算，详情页请自行根据返回的店铺经纬度计算。")
    private double distance;
    @Schema(description = "距离，已格式化的，如：7.9m、1.2km。只有列表才会计算，详情页请自行根据返回的店铺经纬度计算。")
    private String distanceFormat;

    @SuppressWarnings("unused")
    public String getDistanceFormat() {
        if (distance <= 0D) {
            distanceFormat = "";
        } else if (distance < 1000D) {
            distanceFormat = String.format("%.1fm", distance);
        } else {
            distanceFormat = String.format("%.1fkm", distance / 1000);
        }
        return distanceFormat;
    }

    @Schema(description = "商家邀请码")
    private String inviteCode;

}
